package services

import (
	"github.com/mlogclub/simple/sqls"
	"github.com/mlogclub/simple/web/params"

	"bbs-go/internal/models"
	"bbs-go/internal/repositories"
)

var ResourcesService = newResourcesService()

func newResourcesService() *resourcesService {
	return &resourcesService{}
}

type resourcesService struct {
}

func (s *resourcesService) Get(id int64) *models.Resources {
	return repositories.ResourcesRepository.Get(sqls.DB(), id)
}

func (s *resourcesService) Take(where ...interface{}) *models.Resources {
	return repositories.ResourcesRepository.Take(sqls.DB(), where...)
}

func (s *resourcesService) Find(cnd *sqls.Cnd) []models.Resources {
	return repositories.ResourcesRepository.Find(sqls.DB(), cnd)
}

func (s *resourcesService) FindPageByParams(params *params.QueryParams) (list []models.Resources, paging *sqls.Paging) {
	return repositories.ResourcesRepository.FindPageByParams(sqls.DB(), params)
}

func (s *resourcesService) FindPageByCnd(cnd *sqls.Cnd) (list []models.Resources, paging *sqls.Paging) {
	return repositories.ResourcesRepository.FindPageByCnd(sqls.DB(), cnd)
}

func (s *resourcesService) Create(t *models.Resources) error {
	return repositories.ResourcesRepository.Create(sqls.DB(), t)
}

func (s *resourcesService) Update(t *models.Resources) error {
	return repositories.ResourcesRepository.Update(sqls.DB(), t)
}

func (s *resourcesService) Updates(id int64, columns map[string]interface{}) error {
	return repositories.ResourcesRepository.Updates(sqls.DB(), id, columns)
}

func (s *resourcesService) UpdateColumn(id int64, name string, value interface{}) error {
	return repositories.ResourcesRepository.UpdateColumn(sqls.DB(), id, name, value)
}

func (s *resourcesService) Delete(id int64) error {
	return repositories.ResourcesRepository.Delete(sqls.DB(), id)
}
